package com.alan.java7;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

/**
 * @author Alan
 * @create 2017--04--10--17:50
 */
public class QuickReadAndWrite {
    public static void main(String[] a) throws IOException {
        Path path= Paths.get("E:\\svn\\Alan\\java\\alanUtils\\commonUtils\\src\\main\\java\\com\\alan\\java7\\test.txt");
        try(//如果文件存在则直接打开，否则创建文件
            BufferedWriter writer= Files.newBufferedWriter(path, Charset.forName("utf-8"));
            //可以指定打开文件的模式，这里表示追加文件
            //BufferedWriter writer=Files.newBufferedWriter(path, Charset.forName("utf-8"), StandardOpenOption.APPEND);
        ){
            writer.write("hello,java7");
            writer.newLine();
            writer.write("test");
            System.out.println("ok");
        }
        List lines= Files.readAllLines(path);
        System.out.println(lines);
    }
}
